package com.zulu.karaoke.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zulu.karaoke.R;

public class ListSongAdapter extends ArrayAdapter<String>{

	private Context mContext;
	private String[] lstNumber;
	private String[] lstTitle;
	private String[] lstFavourite;
//	private Spinner mSpnVolList;
//	private Spinner mSpnAlphaList;
	
	public ListSongAdapter(Context context, String[] lstNumber, String[] lstTitle, String[] lstFavourite) {
		super(context, R.layout.list_view_list_song, lstNumber);
		this.mContext = context;
		this.lstNumber = lstNumber;
		this.lstTitle = lstTitle;
		this.lstFavourite = lstFavourite;
	}
	
	public ListSongAdapter(Context context, String[] lstNumber, String[] lstTitle) {
		super(context, R.layout.list_view_list_song, lstNumber);
		this.mContext = context;
		this.lstNumber = lstNumber;
		this.lstTitle = lstTitle;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
//		if(position!=0) {
			
			View rowView = inflater.inflate(R.layout.list_view_list_song, parent, false);
			TextView tvNumber = (TextView) rowView.findViewById(R.id.tv_song_number);
			TextView tvTitle = (TextView) rowView.findViewById(R.id.tv_song_title);
			ImageView imgFavourite = (ImageView) rowView.findViewById(R.id.img_favourite_icon);
			
			tvNumber.setText(lstNumber[position]);
			tvTitle.setText(lstTitle[position]);
			if(lstFavourite != null) {
				for (String favouriteNumber : lstFavourite) {
					if(tvNumber.getText().equals(favouriteNumber)) {
						imgFavourite.setBackgroundResource(R.drawable.favorite22);
					}
				}
			}
			
			return rowView;
			
//		} else {
//			View firstView = inflater.inflate(R.layout.spinner_vol_list, parent, false);
//			mSpnVolList = (Spinner)firstView.findViewById(R.id.spn_vol_list);
//			mSpnAlphaList = (Spinner)firstView.findViewById(R.id.spn_alpha_list);
//			getVolList();
//			getVolAlpha();
//			mSpnVolList.setOnItemSelectedListener(new OnItemSelectedListener() {
//
//				@Override
//				public void onItemSelected(AdapterView<?> arg0, View view,
//						int pos, long arg3) {
//					// TODO Auto-generated method stub
//					getSongForVolSelected(pos);
//				}
//
//				@Override
//				public void onNothingSelected(AdapterView<?> arg0) {
//					// TODO Auto-generated method stub
//					
//				}
//			});
//			return firstView;
//		}
	}
	
//	private void getSongForVolSelected(int pos) {
//		Toast.makeText(mContext, mSpnVolList.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();
////		this.clear();
//	}
//	
//	private void getVolList(){
//		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mContext, 
//				R.layout.mysimple_spinner_item, CommonConstants.getListVol());
//		
//		dataAdapter.setDropDownViewResource(R.layout.mysimple_spinner_view);
//		mSpnVolList.setAdapter(dataAdapter);
//	}
//	
//	private void getVolAlpha(){
//		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mContext, 
//				R.layout.mysimple_spinner_item, CommonConstants.getListAlpha());
//		
//		dataAdapter.setDropDownViewResource(R.layout.mysimple_spinner_view);
//		mSpnAlphaList.setAdapter(dataAdapter);
//	}
	
}
